home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Games / Soundboard / CGrayBox.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  3.0 KB  |  108 lines  |  [TEXT/MMCC]

  1. // ===========================================================================
  2. //    CGrayBox.cp                    ©1995 Apple Computer, Inc. All rights reserved.
  3. // ===========================================================================
  4.  
  5. #include "CGrayBox.h"
  6.  
  7. #include <UDrawingUtils.h>
  8. #include <UDrawingState.h>
  9.  
  10.  
  11. // ---------------------------------------------------------------------------
  12. //        • CreateGrayBoxStream
  13. // ---------------------------------------------------------------------------
  14. //    Create a GrayBox object from the data in a Stream
  15.  
  16. CGrayBox*
  17. CGrayBox::CreateGrayBoxStream(
  18.     LStream    *inStream)
  19. {
  20.     return (new CGrayBox(inStream));
  21. }
  22.  
  23.  
  24. // ---------------------------------------------------------------------------
  25. //        • CGrayBox(LStream *)
  26. // ---------------------------------------------------------------------------
  27. //    Constructor
  28. //
  29. //    This class has no new member variables and needs no preparation, so
  30. //    it just calls the constructor for LPane
  31.  
  32. CGrayBox::CGrayBox(
  33.     LStream    *inStream)
  34.         : LView(inStream)
  35. {
  36.     mDrawGrayBkgrnd = false;
  37. }
  38.  
  39. void
  40. CGrayBox::ApplyForeAndBackColors()
  41. {
  42.     LView::ApplyForeAndBackColors();
  43.     if (mDrawGrayBkgrnd)
  44.         ::RGBBackColor(&mLtGray);
  45. }
  46.  
  47.  
  48. // ---------------------------------------------------------------------------
  49. //        • DrawSelf
  50. // ---------------------------------------------------------------------------
  51. //    Draws a filled rectangle. On screens with < 16 colors, the fill is
  52. //    a gray pattern. On screens with >= 16 colors, the fill is a solid
  53. //    gray color.
  54.  
  55. void
  56. CGrayBox::DrawSelf()
  57. {
  58.     Rect    frame;                    // Get bounds of Pane in local coords
  59.     CalcLocalFrameRect(frame);
  60.  
  61.     ApplyForeAndBackColors();
  62.     ::EraseRect(&frame);
  63. }
  64.  
  65. // ---------------------------------------------------------------------------
  66. //        • Draw
  67. // ---------------------------------------------------------------------------
  68. //    Draw a View and all its SubPanes
  69. //
  70. //    inSuperDrawRgnH specifies, in Port coordinates, the portion of the
  71. //    View's SuperView that needs to be drawn. Specify nil to draw the
  72. //    entire View.
  73. //
  74. //    This routine is overridden so that mDrawGrayBkgrnd can be set to draw a
  75. //    gray background when we are drawing to a device with at least 16 colors.
  76.  
  77. void
  78. CGrayBox::Draw(
  79.     RgnHandle    inSuperDrawRgnH)
  80. {
  81.                                         // Don't draw if invisible or unable
  82.                                         //   to put in focus
  83.     if (IsVisible() && FocusDraw()) {
  84.     
  85.         Rect    frame;                    // Get bounds of Pane in local coords
  86.         CalcLocalFrameRect(frame);
  87.         
  88.         StDeviceLoop    theLoop(frame);    // Set up for looping thru each device
  89.         Int16    depth;
  90.         
  91.         while (theLoop.NextDepth(depth)) {
  92.         
  93.                 // At this point, the clipping region is set to the portion
  94.                 // of the Pane that is on the screen with the current
  95.                 // bit depth. Therefore, we can just draw everything, and
  96.                 // let the clipping region restrict the drawing.
  97.                 //
  98.                 // If you are interested in other characteristics of the
  99.                 // current screen device, you can call theLoop.GetCurrentDevice
  100.                 // which will return a GDHandle.
  101.     
  102.             mDrawGrayBkgrnd = (depth >= 4);
  103.             LView::Draw(inSuperDrawRgnH);
  104.         }
  105.         mDrawGrayBkgrnd = false;        // reset back to false
  106.     }
  107. }
  108.